home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / build-bin / fadd < prev    next >
Encoding:
Text File  |  2002-06-04  |  2.8 KB  |  122 lines

  1. #!/bin/sh
  2. # fadd - file add script
  3. # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
  4. # released under gpl.
  5. # $1: full pathname of added file
  6. # $2: directory [inside buildroot] to place file
  7. # ex: fup /home/joseph/myfile col/devel
  8. # opts: -q: quiet [don't print status messages]
  9. #       -f: force [update even when older]
  10. #       -l: language to add to [default: all languages]
  11.  
  12. # BUG: use getopts instead
  13. LANG=
  14. ERROR=0
  15.  
  16. if [ "n$1" = "n-q" ]; then # -q
  17.   QUIET="-q"
  18.   shift
  19. fi
  20.  
  21. if [ "n$1" = "n-f" ]; then # -f
  22.   FORCE="(force)"
  23.   shift
  24. fi
  25.  
  26. if [ "n$1" = "n-l" ]; then # -l
  27.   LANG="$2"
  28.   shift
  29.   shift
  30. fi
  31.  
  32. if [ ! -r "$1" ]; then # file doesn't exist
  33. ( echo `basename $0`: can\'t find \"$1\"
  34.   echo
  35.   echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
  36.   echo adds file to dir of redmond linux build system
  37.   echo -q is quiet, ie don\'t print status messages
  38.   echo -f is force, ie add even if added file is older
  39.   echo -l is language or all if not present ) >&2
  40.   exit 1
  41. fi
  42.  
  43. if [ $# -lt 2 ]; then # no dir given
  44. ( echo `basename $0`: no dir given
  45.   echo perhaps you wanted padd?
  46.   echo
  47.   echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
  48.   echo adds file to dir of redmond linux build system
  49.   echo -q is quiet, ie don\'t print status messages
  50.   echo -f is force, ie add even if added file is older
  51.   echo -l is language or all if not present ) >&2
  52.   exit 1
  53. fi
  54.  
  55. # constants and vars
  56.  
  57. RL_ROOT=/opt/redmondlinux
  58. BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
  59. BUILD_NUM=`cat $BUILD_NUM_FILE`
  60. BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
  61.  
  62. BASENAME=`basename "$1"`
  63.  
  64. cd $BUILD_ROOT
  65. LANG_TO_PROCESS=`echo ${LANG}*`
  66. cd -
  67.  
  68. for lang in $LANG_TO_PROCESS; do
  69.  
  70.   CHANGELOG=$BUILD_ROOT/$lang/CHANGELOG
  71.   ADDED_FILE="$BUILD_ROOT/$lang/$2/$BASENAME"
  72.  
  73.  
  74. # more error checks
  75.  
  76.   if [ ! -d $BUILD_ROOT/$lang/"$2" ]; then # dir doesn't exist
  77.   ( echo `basename $0`: can\'t find \"$BUILD_ROOT/$lang/$2\"
  78.     echo
  79.     echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
  80.     echo adds file to dir of redmond linux build system
  81.     echo -q is quiet, ie don\'t print status messages
  82.     echo -f is force, ie add even if added file is older
  83.     echo -l is language or all if not present ) >&2
  84.     ERROR=1
  85.   fi
  86.  
  87.   if [ -f "$ADDED_FILE" ]; then # added file already exists
  88.   ( echo `basename $0`: already found \"$ADDED_FILE\"
  89.     echo perhaps you need to update it, not add it ) >&2
  90.     ERROR=1
  91.   fi
  92.  
  93.  
  94. # perform the add
  95.  
  96.   cp -f "$1" "$ADDED_FILE"
  97.  
  98.   if [ "$?" -gt 0 ]; then # file copy failed
  99.   ( echo `basename $0`: copy failed
  100.     echo please check permissions and try again ) >&2
  101.     ERROR=1
  102.   fi
  103.  
  104.  
  105. # update changelog
  106.  
  107.   echo + "$2/$BASENAME" >> $CHANGELOG
  108.  
  109.   if [ "$?" -gt 0 ]; then # update changelog failed
  110.   ( echo `basename $0`: update changelog failed
  111.     echo check permissions on $CHANGELOG ) >&2
  112.     ERROR=1
  113.   fi 
  114.  
  115.   [ $QUIET ] || tail -n 1 $CHANGELOG
  116.  
  117. done
  118.  
  119. exit $ERROR
  120.